using System;
using System.Collections;
using System.Drawing;
using System.Drawing.Imaging;
using System.Drawing.Drawing2D;

namespace NikonGuyDesktopLib
{
	/// <summary>
	/// Summary description for Class1.
	/// </summary>
	public class Desktop3D : IDisposable
	{

        ArrayList _images = new ArrayList();

        Size _size;

        int _maxDimLength;

        Random _random;

		public Desktop3D(Size size, int maxDimLength)
		{
            _size = size;
            _maxDimLength = maxDimLength;
            _random = new Random();
		}

        public bool addImage(Image image)
        {
            ImageFrame imf = new ImageFrame(image,new Rectangle(0,0,_size.Width,_size.Height),_maxDimLength,_random,_images);
            if (imf.VALID)
            {
                _images.Add(imf);
                return true;
            }
            else 
            {
                return false;
            }
        }

        public void Dispose()
        {
            foreach (ImageFrame imf in _images)
            {
                imf.Dispose();
            }
        }

        public Image generateImage()
        {
            try 
            {
                Bitmap bitmap = new Bitmap(_size.Width,_size.Height,PixelFormat.Format32bppArgb);
                Graphics g = Graphics.FromImage(bitmap);

				Rectangle rect = new Rectangle(0, 0, _size.Width, _size.Height);
				
				LinearGradientBrush linearBrush = new LinearGradientBrush(rect, Color.Black,
						   Color.DimGray, LinearGradientMode.Vertical);
				g.FillRectangle(linearBrush, rect);

                foreach (ImageFrame imf in _images)
                {
                    imf.Paint(g);
                }

                return bitmap;
            }
            catch (Exception ex)
            {
                Bitmap bitmap2 = new Bitmap(100,30,PixelFormat.Format32bppArgb);
                Graphics g = Graphics.FromImage(bitmap2);
                g.DrawString(ex.ToString(),new Font("Verdana",12),Brushes.Red,new PointF(0,0));
                return bitmap2;
            }
        }
	}
}
